﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using AttributeRouting;
using AttributeRouting.Web.Mvc;
using Phatent.Model.Pages;
using Phatent.Logic.Pages;
namespace Phatent.Website.Areas.Home.Controllers
{
    [RouteArea("Home")]
    public class GeneralController : Controller
    {
        [Route("", IgnoreAreaUrl = true)]
        public ActionResult Index()
        {
            var tops = PageLogic.Gets(new PageQuery() { CaseID = 9, PageSize = 5, PageIndex = 0, Visible = true });
            var trades = PageLogic.Gets(new PageQuery() { CaseID = 10, PageSize = 5, PageIndex = 0, Visible = true });
            tops.AddRange(trades);
            return View(tops);
        }

        [Route("Language")]
        public ActionResult Language()
        {
            if (WebContext.Language == "zh")
                WebContext.Language = "en";
            if (WebContext.Language == "en")
                WebContext.Language = "zh";
            return Redirect("/");
        }

        [Route("Nav")]
        public ActionResult Nav()
        {
            ViewBag.Case = CaseLogic.GetTopCaseByFriendUrl(Request.Path); 
            var lst = CaseLogic.Gets(new CaseQuery() { PID = null, GetItems = true });
            return PartialView("_Nav", lst);
        }

        [Route("SubNav")]
        public ActionResult SubNav()
        {
            var cas = CaseLogic.GetTopCaseByFriendUrl(Request.Path);
            return PartialView("_LeftSubNav", cas);
        }

        [Route("PicList")]
        public ActionResult PicList() 
        {
            var cas = CaseLogic.GetCaseByFriendUrl(Request.Path);
            if (cas.ParentCase == null)
                cas = CaseLogic.GetCaseByParent(cas);
            ViewBag.Case = cas;
            return View();
        }

        [Route("Invest/Announce")]
        [Route("News/Trade")]
        [Route("TxtList")]
        public ActionResult TxtList()
        {
            var cas = CaseLogic.GetCaseByFriendUrl(Request.Path);
            if (cas.ParentCase == null)
                cas = CaseLogic.GetCaseByParent(cas);
            ViewBag.Case = cas;
            return View();
        }

        [Route("Culture")]
        [Route("Culture/{x}")]
        [Route("Invest")]
        [Route("Invest/ConnectUs")]
        [Route("Invest/Company")]
        [Route("Bussiness")]
        [Route("Bussiness/Thing")]
        [Route("Bussiness/Health")]
        [Route("Bussiness/Education")]
        [Route("News/Cooperate")]
        [Route("News/Society")]
        [Route("News/TeamManage")]
        [Route("News/History")]
        [Route("News/Introduce")]
        [Route("Article/{id:int?}")]
        public ActionResult Article(int id = 0)
        {
            var cas = CaseLogic.GetCaseByFriendUrl(Request.Path);
            if (cas.ParentCase == null)
                cas = CaseLogic.GetCaseByParent(cas);
            ViewBag.Case = cas;
            PageModel model = null;
            if (id > 0)
                model = PageLogic.GetPage(id);
            else if (cas != null)
                model = PageLogic.GetTopPage(cas.ID);
            
            return View(model);
        }
    }
}
